package knowse.app.daos;

import org.json.JSONException;
import org.json.JSONObject;

import android.os.Parcel;
import android.os.Parcelable;

public class ChangeDataObject implements Parcelable{

	private String jsonClass;
	private String fileDir;
	private String fileName;
	private Boolean isTextFile;
	private Boolean isBinaryFile;
	private int numChangedLines;
	private int numAddedLines;
	private int numDeletedLines;
	private int numBytesBefore;
	private int numBytesAfter;
	private int commitID;
	
	public void setCommitID(int commitID){this.commitID = commitID;};
	public int getCommitID(){return this.commitID;};
	
	
	public ChangeDataObject(){
		
	}
	
	public ChangeDataObject(JSONObject change) throws JSONException{
		this.jsonClass = change.optString("json_class", "null");
		this.fileDir = change.optString("FileDir", "null");
		this.fileName = change.optString("FileName","null");
		String isTextFile = change.optString("IsTextFile","null");
		this.isTextFile=Boolean.valueOf(isTextFile);		
		String isBinaryFile = change.optString("IsBinaryFile","null");
		this.isBinaryFile=Boolean.valueOf(isBinaryFile);
		this.numChangedLines = change.optInt("NumChangedLines",0);
		this.numAddedLines = change.optInt("NumAddedLines",0);
		this.numDeletedLines = change.optInt("NumDeletedLines",0);
		this.numBytesBefore = change.optInt("NumBytesBefore",0);
		this.numBytesAfter = change.optInt("NumBytesAfter",0);	
	}
	
	
	public ChangeDataObject(String jsonClass, String fileDir, String fileName,
			Boolean isTextFile, Boolean isBinaryFile, int numChangedLines,
			int numAddedLines, int numDeletedLines, int numBytesBefore,
			int numBytesAfter) {
		this.jsonClass = jsonClass;
		this.fileDir = fileDir;
		this.fileName = fileName;
		this.isTextFile = isTextFile;
		this.isBinaryFile = isBinaryFile;
		this.numChangedLines = numChangedLines;
		this.numAddedLines = numAddedLines;
		this.numDeletedLines = numDeletedLines;
		this.numBytesBefore = numBytesBefore;
		this.numBytesAfter = numBytesAfter;
	}

	public String getJsonClass() {
		return jsonClass;
	}

	public void setJsonClass(String jsonClass) {
		this.jsonClass = jsonClass;
	}

	public String getFileDir() {
		return fileDir;
	}

	public void setFileDir(String fileDir) {
		this.fileDir = fileDir;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public Boolean isTextFile() {
		return isTextFile;
	}

	public void setTextFile(Boolean isTextFile) {
		this.isTextFile = isTextFile;
	}

	public Boolean isBinaryFile() {
		return isBinaryFile;
	}

	public void setBinaryFile(Boolean isBinaryFile) {
		this.isBinaryFile = isBinaryFile;
	}

	public int getNumChangedLines() {
		return numChangedLines;
	}

	public void setNumChangedLines(int numChangedLines) {
		this.numChangedLines = numChangedLines;
	}

	public int getNumAddedLines() {
		return numAddedLines;
	}

	public void setNumAddedLines(int numAddedLines) {
		this.numAddedLines = numAddedLines;
	}

	public int getNumDeletedLines() {
		return numDeletedLines;
	}

	public void setNumDeletedLines(int numDeletedLines) {
		this.numDeletedLines = numDeletedLines;
	}

	public int getNumBytesBefore() {
		return numBytesBefore;
	}

	public void setNumBytesBefore(int numBytesBefore) {
		this.numBytesBefore = numBytesBefore;
	}

	public int getNumBytesAfter() {
		return numBytesAfter;
	}

	public void setNumBytesAfter(int numBytesAfter) {
		this.numBytesAfter = numBytesAfter;
	}
	
	@Override
	public String toString() {
		return "ChangeDataObject [jsonClass=" + jsonClass + ", fileDir="
				+ fileDir + ", fileName=" + fileName + ", isTextFile="
				+ isTextFile + ", isBinaryFile=" + isBinaryFile
				+ ", numChangedLines=" + numChangedLines + ", numAddedLines="
				+ numAddedLines + ", numDeletedLines=" + numDeletedLines
				+ ", numBytesBefore=" + numBytesBefore + ", numBytesAfter="
				+ numBytesAfter + "]";
	}

	public int describeContents() {
		return 0;
	}

	public void writeToParcel(Parcel parcel, int flags) {
		parcel.writeString(jsonClass);
		parcel.writeString(fileDir);
		parcel.writeString(fileName);
		parcel.writeString(isTextFile.toString());
		parcel.writeString(isBinaryFile.toString());
		parcel.writeInt(numChangedLines);
		parcel.writeInt(numAddedLines);
		parcel.writeInt(numDeletedLines);
		parcel.writeInt(numBytesBefore);
		parcel.writeInt(numBytesAfter);	
	}
	
	public static final Parcelable.Creator<ChangeDataObject> CREATOR= new Creator<ChangeDataObject>(){

		public ChangeDataObject createFromParcel(Parcel source) {
			ChangeDataObject changeDataObj=new ChangeDataObject();
			changeDataObj.jsonClass=source.readString();
			changeDataObj.fileDir=source.readString();
			changeDataObj.fileName=source.readString();
			changeDataObj.isTextFile=Boolean.valueOf(source.readString());
			changeDataObj.isBinaryFile=Boolean.valueOf(source.readString());
			changeDataObj.numChangedLines=source.readInt();
			changeDataObj.numAddedLines=source.readInt();
			changeDataObj.numDeletedLines=source.readInt();
			changeDataObj.numBytesBefore=source.readInt();
			changeDataObj.numBytesAfter=source.readInt();
			return changeDataObj;
		};

		public ChangeDataObject[] newArray(int size) {
			return new ChangeDataObject[size];
		}
		
		
	};
	

}

